/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TapRoomKegSaleForm.java
 *
 * Created on Feb 10, 2011, 12:51:23 PM
 */

package gbbmgmt;

import java.util.*;
import org.jdesktop.application.Action;
import javax.swing.JOptionPane;

/**
 *
 * @author dchapman
 */
public class TapRoomKegSaleForm extends javax.swing.JFrame {

    public ArrayList<String[]> TRCustomers;
    public ArrayList<String[]> Beers;
    public ArrayList<String[]> Discounts;

    String OrderCSV = "";
    String OrderText = "";

    /** Creates new form TapRoomKegSaleForm */
    public TapRoomKegSaleForm() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabelQtr = new javax.swing.JLabel();
        jLabelSix = new javax.swing.JLabel();
        jLabelHalf = new javax.swing.JLabel();
        jTextFieldNumQtr = new javax.swing.JTextField();
        jTextFieldNumHalf = new javax.swing.JTextField();
        jTextFieldNumSix = new javax.swing.JTextField();
        jLabelKegs = new javax.swing.JLabel();
        jLabelDisc = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jButtonCustFirst = new javax.swing.JButton();
        jButtonCustPrev = new javax.swing.JButton();
        jButtonCustLast = new javax.swing.JButton();
        jButtonCustNext = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jTextFieldTRSID = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jTextFieldCustName = new javax.swing.JTextField();
        jTextFieldCustAddr = new javax.swing.JTextField();
        jTextFieldCustPhone = new javax.swing.JTextField();
        jDateChooser1 = new com.toedter.calendar.JDateChooser();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator2 = new javax.swing.JSeparator();
        jLabelBeer = new javax.swing.JLabel();
        jButtonAddBeer = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JSeparator();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jSeparator4 = new javax.swing.JSeparator();
        jButtonModData = new javax.swing.JButton();
        jButtonExit = new javax.swing.JButton();
        jButtonNewEntry = new javax.swing.JButton();
        jButtonSubNewEntry = new javax.swing.JButton();
        jButtonReset = new javax.swing.JButton();
        jCheckBoxTRSRtr = new javax.swing.JCheckBox();
        jComboBoxSC = new javax.swing.JComboBox();
        jComboBoxBeer = new javax.swing.JComboBox();
        jComboBoxDisc = new javax.swing.JComboBox();
        jButtonOverRide = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(gbbmgmt.GBBMGMTApp.class).getContext().getResourceMap(TapRoomKegSaleForm.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N

        jLabelQtr.setText(resourceMap.getString("jLabelQtr.text")); // NOI18N
        jLabelQtr.setName("jLabelQtr"); // NOI18N

        jLabelSix.setText(resourceMap.getString("jLabelSix.text")); // NOI18N
        jLabelSix.setName("jLabelSix"); // NOI18N

        jLabelHalf.setText(resourceMap.getString("jLabelHalf.text")); // NOI18N
        jLabelHalf.setName("jLabelHalf"); // NOI18N

        jTextFieldNumQtr.setName("jTextFieldNumQtr"); // NOI18N

        jTextFieldNumHalf.setName("jTextFieldNumHalf"); // NOI18N

        jTextFieldNumSix.setName("jTextFieldNumSix"); // NOI18N

        jLabelKegs.setText(resourceMap.getString("jLabelKegs.text")); // NOI18N
        jLabelKegs.setName("jLabelKegs"); // NOI18N

        jLabelDisc.setText(resourceMap.getString("jLabelDisc.text")); // NOI18N
        jLabelDisc.setName("jLabelDisc"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(gbbmgmt.GBBMGMTApp.class).getContext().getActionMap(TapRoomKegSaleForm.class, this);
        jButtonCustFirst.setAction(actionMap.get("FirstRecord")); // NOI18N
        jButtonCustFirst.setText(resourceMap.getString("jButtonCustFirst.text")); // NOI18N
        jButtonCustFirst.setName("jButtonCustFirst"); // NOI18N

        jButtonCustPrev.setAction(actionMap.get("getPrev")); // NOI18N
        jButtonCustPrev.setText(resourceMap.getString("jButtonCustPrev.text")); // NOI18N
        jButtonCustPrev.setName("jButtonCustPrev"); // NOI18N

        jButtonCustLast.setAction(actionMap.get("LastRecord")); // NOI18N
        jButtonCustLast.setText(resourceMap.getString("jButtonCustLast.text")); // NOI18N
        jButtonCustLast.setName("jButtonCustLast"); // NOI18N

        jButtonCustNext.setAction(actionMap.get("getNext")); // NOI18N
        jButtonCustNext.setText(resourceMap.getString("jButtonCustNext.text")); // NOI18N
        jButtonCustNext.setName("jButtonCustNext"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel13.setText(resourceMap.getString("jLabel13.text")); // NOI18N
        jLabel13.setName("jLabel13"); // NOI18N

        jTextFieldTRSID.setEditable(false);
        jTextFieldTRSID.setName("jTextFieldTRSID"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        jTextFieldCustName.setText(resourceMap.getString("jTextFieldCustName.text")); // NOI18N
        jTextFieldCustName.setName("jTextFieldCustName"); // NOI18N

        jTextFieldCustAddr.setText(resourceMap.getString("jTextFieldCustAddr.text")); // NOI18N
        jTextFieldCustAddr.setName("jTextFieldCustAddr"); // NOI18N

        jTextFieldCustPhone.setText(resourceMap.getString("jTextFieldCustPhone.text")); // NOI18N
        jTextFieldCustPhone.setName("jTextFieldCustPhone"); // NOI18N

        jDateChooser1.setName("jDateChooser1"); // NOI18N

        jSeparator1.setName("jSeparator1"); // NOI18N

        jSeparator2.setName("jSeparator2"); // NOI18N

        jLabelBeer.setText(resourceMap.getString("jLabelBeer.text")); // NOI18N
        jLabelBeer.setName("jLabelBeer"); // NOI18N

        jButtonAddBeer.setAction(actionMap.get("AddBeer")); // NOI18N
        jButtonAddBeer.setText(resourceMap.getString("jButtonAddBeer.text")); // NOI18N
        jButtonAddBeer.setName("jButtonAddBeer"); // NOI18N

        jSeparator3.setName("jSeparator3"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jTextArea1.setName("jTextArea1"); // NOI18N
        jScrollPane1.setViewportView(jTextArea1);

        jSeparator4.setName("jSeparator4"); // NOI18N

        jButtonModData.setAction(actionMap.get("ModifyRecord")); // NOI18N
        jButtonModData.setText(resourceMap.getString("jButtonModData.text")); // NOI18N
        jButtonModData.setName("jButtonModData"); // NOI18N

        jButtonExit.setAction(actionMap.get("ExitTRS")); // NOI18N
        jButtonExit.setText(resourceMap.getString("jButtonExit.text")); // NOI18N
        jButtonExit.setName("jButtonExit"); // NOI18N

        jButtonNewEntry.setAction(actionMap.get("AddNewRecord")); // NOI18N
        jButtonNewEntry.setText(resourceMap.getString("jButtonNewEntry.text")); // NOI18N
        jButtonNewEntry.setName("jButtonNewEntry"); // NOI18N

        jButtonSubNewEntry.setAction(actionMap.get("SubmitTRS")); // NOI18N
        jButtonSubNewEntry.setText(resourceMap.getString("jButtonSubNewEntry.text")); // NOI18N
        jButtonSubNewEntry.setName("jButtonSubNewEntry"); // NOI18N

        jButtonReset.setAction(actionMap.get("ResetTRS")); // NOI18N
        jButtonReset.setText(resourceMap.getString("jButtonReset.text")); // NOI18N
        jButtonReset.setName("jButtonReset"); // NOI18N

        jCheckBoxTRSRtr.setText(resourceMap.getString("jCheckBoxTRSRtr.text")); // NOI18N
        jCheckBoxTRSRtr.setName("jCheckBoxTRSRtr"); // NOI18N

        jComboBoxSC.setName("jComboBoxSC"); // NOI18N
        jComboBoxSC.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
                jComboBoxSCPopupMenuWillBecomeInvisible(evt);
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
            }
        });

        jComboBoxBeer.setName("jComboBoxBeer"); // NOI18N
        jComboBoxBeer.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
                jComboBoxBeerPopupMenuWillBecomeInvisible(evt);
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
            }
        });

        jComboBoxDisc.setName("jComboBoxDisc"); // NOI18N

        jButtonOverRide.setAction(actionMap.get("OverRide")); // NOI18N
        jButtonOverRide.setText(resourceMap.getString("jButtonOverRide.text")); // NOI18N
        jButtonOverRide.setName("jButtonOverRide"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jComboBoxSC, 0, 307, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButtonCustFirst)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonCustPrev)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonCustNext)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonCustLast)
                .addContainerGap())
            .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 633, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel10)
                    .addComponent(jLabel9)
                    .addComponent(jLabel5)
                    .addComponent(jLabel13))
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(jTextFieldTRSID, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jCheckBoxTRSRtr)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 90, Short.MAX_VALUE)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jTextFieldCustPhone, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 491, Short.MAX_VALUE)
                    .addComponent(jTextFieldCustAddr, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 491, Short.MAX_VALUE)
                    .addComponent(jTextFieldCustName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 491, Short.MAX_VALUE))
                .addContainerGap())
            .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 633, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelBeer)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jComboBoxBeer, 0, 350, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabelDisc)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jComboBoxDisc, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelKegs)
                .addGap(18, 18, 18)
                .addComponent(jLabelHalf)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextFieldNumHalf, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(12, 12, 12)
                .addComponent(jLabelQtr)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextFieldNumQtr, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(14, 14, 14)
                .addComponent(jLabelSix)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextFieldNumSix, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 89, Short.MAX_VALUE)
                .addComponent(jButtonReset)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonAddBeer)
                .addContainerGap())
            .addComponent(jSeparator3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 633, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 613, Short.MAX_VALUE)
                .addContainerGap())
            .addComponent(jSeparator4, javax.swing.GroupLayout.DEFAULT_SIZE, 633, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButtonModData)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButtonNewEntry)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonSubNewEntry)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonOverRide)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 146, Short.MAX_VALUE)
                .addComponent(jButtonExit)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel1)
                    .addComponent(jButtonCustFirst)
                    .addComponent(jButtonCustPrev)
                    .addComponent(jButtonCustNext)
                    .addComponent(jButtonCustLast)
                    .addComponent(jComboBoxSC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel13)
                        .addComponent(jLabel2)
                        .addComponent(jTextFieldTRSID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jCheckBoxTRSRtr))
                    .addComponent(jDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldCustName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldCustAddr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldCustPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabelBeer)
                    .addComponent(jLabelDisc)
                    .addComponent(jComboBoxBeer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBoxDisc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelKegs)
                    .addComponent(jLabelHalf)
                    .addComponent(jTextFieldNumHalf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelQtr)
                    .addComponent(jTextFieldNumQtr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelSix)
                    .addComponent(jTextFieldNumSix, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonAddBeer)
                    .addComponent(jButtonReset))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(7, 7, 7)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonModData)
                    .addComponent(jButtonExit)
                    .addComponent(jButtonNewEntry)
                    .addComponent(jButtonSubNewEntry)
                    .addComponent(jButtonOverRide))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jComboBoxSCPopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_jComboBoxSCPopupMenuWillBecomeInvisible
        // TODO add your handling code here:
        String Itm = jComboBoxSC.getSelectedItem().toString();

        for(String s[] : TRCustomers){
            String Match = s[0] + " - " + s[1];
            if (Match.equals(Itm)) {
                DBA.openDBCon();
                DBA.GetTRoomSaleData(s[0]);
                DBA.closeDBCon();
            }
        }
        SetData();
    }//GEN-LAST:event_jComboBoxSCPopupMenuWillBecomeInvisible

    private void jComboBoxBeerPopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_jComboBoxBeerPopupMenuWillBecomeInvisible
        // TODO add your handling code here:
        ResetValues();

        String sel = jComboBoxBeer.getSelectedItem().toString();
        String BeerID = "0";

        for(String s[] : Beers){
            if (s[1].equals(sel)) {
                BeerID = s[0];
            }
        }

        DBA.openDBCon();

        //Check inventory of beer to see what to enable and what not to.
        String BIID = DBA.ReturnKey("BeerInventory", "BIBId", BeerID, "BIId");

        DBA.GetBeerInventoryData(BIID);

        DBA.closeDBCon();

        if(DBA.BIHalf > 0){
            jTextFieldNumHalf.setEnabled(true);
        }
        if(DBA.BIQtr > 0){
            jTextFieldNumQtr.setEnabled(true);
        }
        if(DBA.BISix > 0){
            jTextFieldNumSix.setEnabled(true);
        }
    }//GEN-LAST:event_jComboBoxBeerPopupMenuWillBecomeInvisible

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new TapRoomKegSaleForm().setVisible(true);
            }
        });
    }

    public void LoadList(){
        DBA.openDBCon();
        TRCustomers = DBA.RunSQLQuery("SELECT TRSId,TRSName FROM TRoomSale");
        Beers = DBA.RunSQLQuery("SELECT BId,BName FROM Beer");
        Discounts = DBA.RunSQLQuery("SELECT DiscID,DiscName FROM DiscountCode");
        DBA.closeDBCon();

        for(String s[] : TRCustomers){
            jComboBoxSC.addItem(s[0] + " - " + s[1]);
        }
        jComboBoxBeer.addItem("");
        for(String s[] : Beers){
            jComboBoxBeer.addItem(s[1]);
        }

        for(String s[] : Discounts){
            jComboBoxDisc.addItem(s[1]);
        }

        jComboBoxBeer.setSelectedIndex(0);
        jComboBoxDisc.setSelectedIndex(0);

        FirstRecord();
    }

    public void SetData(){
        jComboBoxBeer.setSelectedIndex(0);
        jTextFieldTRSID.setText(Integer.toString(DBA.TRSId));
        jTextFieldCustName.setText(DBA.TRSName);
        jTextFieldCustAddr.setText(DBA.TRSAddr);
        jTextFieldCustPhone.setText(DBA.TRSPhone);
        jDateChooser1.setDate(DBA.TRSDate);

        jTextFieldNumHalf.setText("0");
        jTextFieldNumQtr.setText("0");
        jTextFieldNumSix.setText("0");

        String SOOUT = DBA.GetSalesOrderString(DBA.TRSCSV);
        SOOUT += "\nTotal Cost: $" + DBA.SOCCost;
        jTextArea1.setText(SOOUT);

        jCheckBoxTRSRtr.setSelected(DBA.TRSRtn);

        //Hide all fields to do with new entry until ready.
        jLabelBeer.setVisible(false);
        jLabelKegs.setVisible(false);
        jLabelDisc.setVisible(false);
        jLabelHalf.setVisible(false);
        jLabelQtr.setVisible(false);
        jLabelSix.setVisible(false);
        jButtonSubNewEntry.setVisible(false);
        jButtonAddBeer.setVisible(false);
        jButtonReset.setVisible(false);
        jComboBoxBeer.setVisible(false);
        jComboBoxDisc.setVisible(false);
        jTextFieldNumHalf.setVisible(false);
        jTextFieldNumQtr.setVisible(false);
        jTextFieldNumSix.setVisible(false);
        jButtonOverRide.setVisible(false);
        ResetValues();

    }

    public void SetEntryData(){
        jTextFieldNumHalf.setText("0");
        jTextFieldNumQtr.setText("0");
        jTextFieldNumSix.setText("0");
        ResetValues();
        jComboBoxBeer.setSelectedIndex(0);
    }

    @Action
    public void FirstRecord() {
        jComboBoxSC.setSelectedIndex(0);

        String Itm = jComboBoxSC.getSelectedItem().toString();

        for(String s[] : TRCustomers){
            String Match = s[0] + " - " + s[1];
            if (Match.equals(Itm)) {
                DBA.openDBCon();
                DBA.GetTRoomSaleData(s[0]);
                DBA.closeDBCon();
            }
        }
        SetData();
    }

    @Action
    public void LastRecord() {
        jComboBoxSC.setSelectedIndex(jComboBoxSC.getItemCount()-1);

        String Itm = jComboBoxSC.getSelectedItem().toString();

        for(String s[] : TRCustomers){
            String Match = s[0] + " - " + s[1];
            if (Match.equals(Itm)) {
                DBA.openDBCon();
                DBA.GetTRoomSaleData(s[0]);
                DBA.closeDBCon();
            }
        }
        SetData();
    }

    @Action
    public void getPrev() {
        if(jComboBoxSC.getSelectedIndex()>=1){
            jComboBoxSC.setSelectedIndex(jComboBoxSC.getSelectedIndex()-1);
        }

        String Itm = jComboBoxSC.getSelectedItem().toString();

        for(String s[] : TRCustomers){
            String Match = s[0] + " - " + s[1];
            if (Match.equals(Itm)) {
                DBA.openDBCon();
                DBA.GetTRoomSaleData(s[0]);
                DBA.closeDBCon();
            }
        }
        SetData();
    }

    @Action
    public void getNext() {
        if(jComboBoxSC.getSelectedIndex() <= (jComboBoxSC.getItemCount()-2)){
            jComboBoxSC.setSelectedIndex(jComboBoxSC.getSelectedIndex()+1);
        }

        String Itm = jComboBoxSC.getSelectedItem().toString();

        for(String s[] : TRCustomers){
            String Match = s[0] + " - " + s[1];
            if (Match.equals(Itm)) {
                DBA.openDBCon();
                DBA.GetTRoomSaleData(s[0]);
                DBA.closeDBCon();
            }
        }
        SetData();
    }

    @Action
    public void ExitTRS() {
        dispose();
    }

    @Action
    public void AddBeer() {
        String ItmBeer = jComboBoxBeer.getSelectedItem().toString();
        String ItmDisc = jComboBoxDisc.getSelectedItem().toString();

        String BeerID = null;
        String DiscID = null;

        //Set All Variables for addint to strings.
        for(String s[] : Beers){
            if (s[1].equals(ItmBeer)) {
                BeerID = s[0];
            }
        }

        for(String s[] : Discounts){
            if (s[1].equals(ItmDisc)) {
                DiscID = s[0];
            }
        }

        String NumHalf = jTextFieldNumHalf.getText();
        String NumQtr = jTextFieldNumQtr.getText();
        String NumSix = jTextFieldNumSix.getText();

        int nhlf = Integer.parseInt(NumHalf);
        int nqtr = Integer.parseInt(NumQtr);
        int nsix = Integer.parseInt(NumSix);

        boolean orderkosher = true;

        if (nhlf > DBA.BIHalf) orderkosher = false;
        if (nqtr > DBA.BIQtr) orderkosher = false;
        if (nsix > DBA.BISix) orderkosher = false;

        if (ItmBeer.equals("")) orderkosher = false;

        if (orderkosher == false){
            int response = JOptionPane.showConfirmDialog(null,
                "Check order, not enough beer in stock!",
                "Warning",JOptionPane.WARNING_MESSAGE);

            return;
        }

        //Perform database queries.
        DBA.openDBCon();
        DBA.GetBeerData(BeerID);
        DBA.GetDiscountCodeData(DiscID);
        DBA.GetEmployeeData(Integer.toString(Global.userID));
        DBA.closeDBCon();

        //If a value was entered fill in the order text.
        if (!jTextFieldNumHalf.getText().equals("0") ||
                !jTextFieldNumQtr.getText().equals("0") ||
                !jTextFieldNumSix.getText().equals("0")){
            OrderText += DBA.BName + " - ";

            if (!jTextFieldNumHalf.getText().equals("0")){
                OrderText += jTextFieldNumHalf.getText() + "x 1/2 BBL Keg(s), ";
            }
            if (!jTextFieldNumQtr.getText().equals("0")){
                OrderText += jTextFieldNumQtr.getText() + "x 1/4 BBL Keg(s), ";
            }
            if (!jTextFieldNumSix.getText().equals("0")){
                OrderText += jTextFieldNumSix.getText() + "x 1/6 BBL Keg(s), ";
            }

            if (!DBA.DiscName.equals("None")){
                OrderText += "Discount: " + DBA.DiscName;
            }

            OrderText += "\n";

            jTextArea1.setText(OrderText);
            jComboBoxDisc.setSelectedIndex(0);

            //Add info to the Sales Order CSV.
            OrderCSV += BeerID + "," + NumHalf + "," + NumQtr +
                    "," + NumSix + "," + DiscID + ",";
        }
        
        SetEntryData();
    }

    public void ResetValues(){
        jTextFieldNumHalf.setEnabled(false);
        jTextFieldNumQtr.setEnabled(false);
        jTextFieldNumSix.setEnabled(false);
    }

    @Action
    public void ResetTRS() {
        int response = JOptionPane.showConfirmDialog(null,
                "This will reset current Sales Order, continue?",
                "Warning",JOptionPane.WARNING_MESSAGE);

        if (response == 0){
            SetEntryData();
            OrderText = "";
            OrderCSV = "";
            jTextArea1.setText(OrderText);
            jComboBoxDisc.setSelectedIndex(0);
        }
    }

    @Action
    public void ModifyRecord() {
        //TODO: Look for changes on this page and update the entry in the database.
        int response = JOptionPane.showConfirmDialog(null,
                "This will modify customer data, continue?",
                "Warning",JOptionPane.WARNING_MESSAGE);

        if (response == 0){
            //User wants to update database, check for differences.
            DBA.openDBCon();
            String TRSID = jTextFieldTRSID.getText();

            if(!jTextFieldCustName.getText().equals(DBA.TRSName)){
                String query = "UPDATE TRoomSale SET TRSName = '" +
                        jTextFieldCustName.getText() + "'WHERE TRSId = '" +
                        TRSID + "'";
                DBA.RunSQLUpdateQuery(query);
            }
            if(!jTextFieldCustAddr.getText().equals(DBA.TRSAddr)){
                String query = "UPDATE TRoomSale SET TRSAddr = '" +
                        jTextFieldCustAddr.getText() + "'WHERE TRSId = '" +
                        TRSID + "'";
                DBA.RunSQLUpdateQuery(query);
            }
            if(!jTextFieldCustPhone.getText().equals(DBA.TRSPhone)){
                String query = "UPDATE TRoomSale SET TRSPhone = '" +
                        jTextFieldCustPhone.getText() + "'WHERE TRSId = '" +
                        TRSID + "'";
                DBA.RunSQLUpdateQuery(query);
            }
            if(DBA.TRSRtn != jCheckBoxTRSRtr.isSelected()){
                String Value = "0";
                if (jCheckBoxTRSRtr.isSelected()){
                    Value = "1";
                }
                String query = "UPDATE TRoomSale SET TRSRtn = '" +
                        Value + "'WHERE TRSId = '" +
                        TRSID + "'";
                DBA.RunSQLUpdateQuery(query);
            }

            java.util.Date dte = jDateChooser1.getDate();
            java.sql.Date TRSDate = new java.sql.Date( dte.getTime() );
            if(TRSDate != DBA.TRSDate){
                String query = "UPDATE TRoomSale SET TRSDate = '" +
                        TRSDate.toString() + "'WHERE TRSId = '" +
                        TRSID + "'";
                DBA.RunSQLUpdateQuery(query);
            }
            

            //Update screen with new info.
            DBA.GetTRoomSaleData(TRSID);
            DBA.closeDBCon();

            SetData();
        }
    }

    @Action
    public void AddNewRecord() {

        //Set Defaut fields.
        jTextFieldTRSID.setText("");
        jTextFieldCustAddr.setText("");
        jTextFieldCustName.setText("");
        jTextFieldCustPhone.setText("");
        jTextFieldNumHalf.setText("0");
        jTextFieldNumQtr.setText("0");
        jTextFieldNumSix.setText("0");
        jTextArea1.setText("");

        //Get todays date.
        java.util.Date dt = new java.util.Date();
        jDateChooser1.setDate(dt);

        //Hide all fields to do with new entry until ready.
        jLabelBeer.setVisible(true);
        jLabelKegs.setVisible(true);
        jLabelDisc.setVisible(true);
        jLabelHalf.setVisible(true);
        jLabelQtr.setVisible(true);
        jLabelSix.setVisible(true);
        jButtonSubNewEntry.setVisible(true);
        jButtonAddBeer.setVisible(true);
        jButtonReset.setVisible(true);
        jComboBoxBeer.setVisible(true);
        jComboBoxDisc.setVisible(true);
        jTextFieldNumHalf.setVisible(true);
        jTextFieldNumQtr.setVisible(true);
        jTextFieldNumSix.setVisible(true);
        jButtonOverRide.setVisible(true);

        //Hide unrelivant buttons.
        jButtonModData.setVisible(false);
        jButtonNewEntry.setVisible(false);
        jComboBoxSC.setVisible(false);
        jButtonCustFirst.setVisible(false);
        jButtonCustLast.setVisible(false);
        jButtonCustNext.setVisible(false);
        jButtonCustPrev.setVisible(false);
        jLabel1.setVisible(false);


    }

    @Action
    public void SubmitTRS() {
        int response = JOptionPane.showConfirmDialog(null,
                "Are you sure you want to create a new Tap Room Sale?",
                "Warning",JOptionPane.WARNING_MESSAGE);

        if (response == 0){
            //Setup data.
            String SOCSV = "";
            String CustID = "15";

            java.util.Date dte = jDateChooser1.getDate();
            java.sql.Date SODate = new java.sql.Date( dte.getTime() );

            String[] sarry = OrderCSV.split(",");
            int count = 0;

            int NumLines = 0;

            String SNotes = "Taproom keg sale added from app by " + DBA.EmpFirstName + " " + DBA.EmpLastName;

            String fields = "CustID,SDate,SNotes,BeerID,NumHalf,NumQtr,NumSix,SDisc,NumTT,NumTW,NumSF";

            while (count < sarry.length){
                String query = "'" + CustID + "','" +
                        SODate + "','" +
                        SNotes + "','" +
                        sarry[count] + "','" +
                        sarry[count+1] + "','" +
                        sarry[count+2] + "','" +
                        sarry[count+3] + "','" +
                        sarry[count+4] + "','" +
                        "0" + "','" +
                        "0" + "','" +
                        "0" + "'";

                count = count + 5;

                DBA.openDBCon();
                DBA.RunSQLInsertQuery("Sales",fields,query);
                //SOCSV += DBA.GetLastIndex("Sales", "SId") + ",";
                SOCSV += Integer.toString(Global.lastInsertID) + ",";
                
                //Update inventory.
                //DBA.ModifyInventoryFromSalesLine(DBA.GetLastIndex("Sales", "SId"));
                DBA.ModifyInventoryFromSalesLine(Integer.toString(Global.lastInsertID));

                DBA.closeDBCon();

                NumLines++;
            }

            //Sales Lines Added, now add list to SalesOrder Table.
            //trim last comma off of SOCSV
            String NewSOCSV = SOCSV.substring(0,SOCSV.length() - 1);

            fields = "TRSDate,TRSName,TRSAddr,TRSPhone,TRSRtn,TRSCSV";

            String TRSRtn = "0";

            String query = "'" + SODate + "','" +
                    jTextFieldCustName.getText() + "','" +
                    jTextFieldCustAddr.getText() + "','" +
                    jTextFieldCustPhone.getText() + "','" +
                    TRSRtn + "','" +
                    NewSOCSV + "'";
            DBA.openDBCon();
            DBA.RunSQLInsertQuery("TRoomSale", fields, query);
            DBA.closeDBCon();

            //Reset the data on the screen.
            SetData();
            OrderText = "";
            OrderCSV = "";
            jTextArea1.setText(OrderText);
            jComboBoxDisc.setSelectedIndex(0);

            //Get todays date.
            java.util.Date dt = new java.util.Date();
            jDateChooser1.setDate(dt);

            //Hide all fields to do with new entry until ready.
            jLabelBeer.setVisible(false);
            jLabelKegs.setVisible(false);
            jLabelDisc.setVisible(false);
            jLabelHalf.setVisible(false);
            jLabelQtr.setVisible(false);
            jLabelSix.setVisible(false);
            jButtonSubNewEntry.setVisible(false);
            jButtonAddBeer.setVisible(false);
            jButtonReset.setVisible(false);
            jComboBoxBeer.setVisible(false);
            jComboBoxDisc.setVisible(false);
            jTextFieldNumHalf.setVisible(false);
            jTextFieldNumQtr.setVisible(false);
            jTextFieldNumSix.setVisible(false);

            //show relivant buttons.
            jButtonModData.setVisible(true);
            jButtonNewEntry.setVisible(true);
            jComboBoxSC.setVisible(true);
            jButtonCustFirst.setVisible(true);
            jButtonCustLast.setVisible(true);
            jButtonCustNext.setVisible(true);
            jButtonCustPrev.setVisible(true);
            jLabel1.setVisible(true);

            //Reload the list.
            jComboBoxSC.removeAllItems();
            LoadList();
            LastRecord();
        }
    }

    @Action
    public void OverRide() {
        int response = JOptionPane.showConfirmDialog(null,
                "This will over ride existing inventory, are you sure? \n" +
                "OverRide will be logged if you continue.",
                "Warning",JOptionPane.WARNING_MESSAGE);

        if (response == 0){
            jTextFieldNumHalf.setEnabled(true);
            jTextFieldNumQtr.setEnabled(true);
            jTextFieldNumSix.setEnabled(true);
            DBA.BIHalf = 1000000;
            DBA.BIQtr = 1000000;
            DBA.BISix = 1000000;
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAddBeer;
    private javax.swing.JButton jButtonCustFirst;
    private javax.swing.JButton jButtonCustLast;
    private javax.swing.JButton jButtonCustNext;
    private javax.swing.JButton jButtonCustPrev;
    private javax.swing.JButton jButtonExit;
    private javax.swing.JButton jButtonModData;
    private javax.swing.JButton jButtonNewEntry;
    private javax.swing.JButton jButtonOverRide;
    private javax.swing.JButton jButtonReset;
    private javax.swing.JButton jButtonSubNewEntry;
    private javax.swing.JCheckBox jCheckBoxTRSRtr;
    private javax.swing.JComboBox jComboBoxBeer;
    private javax.swing.JComboBox jComboBoxDisc;
    private javax.swing.JComboBox jComboBoxSC;
    private com.toedter.calendar.JDateChooser jDateChooser1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel jLabelBeer;
    private javax.swing.JLabel jLabelDisc;
    private javax.swing.JLabel jLabelHalf;
    private javax.swing.JLabel jLabelKegs;
    private javax.swing.JLabel jLabelQtr;
    private javax.swing.JLabel jLabelSix;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextFieldCustAddr;
    private javax.swing.JTextField jTextFieldCustName;
    private javax.swing.JTextField jTextFieldCustPhone;
    private javax.swing.JTextField jTextFieldNumHalf;
    private javax.swing.JTextField jTextFieldNumQtr;
    private javax.swing.JTextField jTextFieldNumSix;
    private javax.swing.JTextField jTextFieldTRSID;
    // End of variables declaration//GEN-END:variables

}
